@extends('admin.layouts._menu')
@section('content')
    {{--@include('layouts._message')--}}
    <div class="card">
        <div class="card-body">
            <ul class="nav nav-tabs nav-overflow header-tabs">
                <li class="nav-item">
                    <a href="{{route('admin.user.index')}}" class="nav-link pb-3 active">
                        用户列表
                    </a>
                </li>
                <li class="nav-item mt-4">
                    <form action="{{route('admin.search.user')}}" method="post">
                        @csrf
                        <div style="margin-left: 560px">
                            <input type="text" name="name">
                            <button class="btn btn-light btn-sm">搜索</button>
                        </div>
                    </form>
                </li>
            </ul>
        </div>
        <div class="card-body small">
            <table class="table">
                <thead>
                <tr>
                    <th>编号</th>
                    <th>用户名</th>
                    <th>用户昵称</th>
                    <th>注册时间</th>
                    <th>角色</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                @foreach($users as $user)
                    {{--@if($user['system']==0)--}}
                        <tr>
                            <td scope="row">{{$user['id']}}</td>
                            <td>{{$user['name']}}</td>
                            <td>{{$user['nickname']}}</td>
                            <td>{{$user['created_at']->format('Y/m/d')}}</td>
                            <td>
                                @foreach($user->role as $role)
                                    <a href="{{route('admin.role.edit',$role)}}" class="btn btn-primary btn-sm">{{$role['title']}}</a>
                                @endforeach
                            </td>
                            <td class="text-right">
                                <div class="btn-group btn-group-sm" user="group" aria-label="First group">
                                    {{--<a href="{{route('admin.user.edit',$user)}}" class="btn btn-white">编辑用户</a>--}}
                                    <a href="{{route('admin.user.role',$user)}}" class="btn btn-light">分配角色</a>
                                    {{--@if($user['id']!=1)--}}
                                    {{--<button type="button" class="btn btn-white" onclick="del(this)">删除用户</button>--}}
                                    {{--@endif--}}
                                    <form action="{{route('admin.user.destroy',$user)}}" method="post">
                                        @csrf @method('DELETE')
                                    </form>
                                </div>
                            </td>
                        </tr>
                    {{--@endif--}}
                @endforeach
                </tbody>
            </table>
        </div>
        <div class="card_body">
            {{$users->links()}}
        </div>
    </div>
@endsection

@push('js')
    <script>
        function del(obj) {
            require(['hdjs'], function (hdjs) {
                hdjs.confirm("确定删除角色吗？", function () {
                    $(obj).next().submit();
                })
            })
        }
    </script>
@endpush

